// 商品路由
const express = require('express');
const pool = require('../../pool.js');
const goods = express.Router();

goods.get('/show', (req, res) => { 
    // console.log('hahah');
    res.send('商品路由');
});

/**first-Floor */
goods.get('/first',(req, res) => {
    let sql = 'select commodity,price,img from goods'
    // console.log(sql);
    pool.query(sql, (err,result) => { 
        if (err) {
            throw err;
        }
        // console.log(result);
        res.send(result);
    });
});
/**second-Floor */
/**forth-Floor */
/**用户登录 */
goods.post('/login', (req,res) => { 
    pool.query('select * from customer where uname=? and upwd=?', [req.body.uname, req.body.upwd], (err, r) => { 
        if (err) {
            throw err;
        }
        res.send(r);
    });
});
/**用户注册 */
goods.post('/register', (req, res) => { 
    pool.query('insert customer set uname=?,upwd=?', [req.body.uname, req.body.upwd], (err, r) => { 
        if (err) {
            throw err;
        }
        res.send(r);
    });
});
module.exports = goods;